home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Portable Parts / Arrays / ArrayHeap.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  590 b   |  38 lines

  1. // ArrayHeap.h
  2.  
  3. #ifndef ArrayHeap_h
  4. #define ArrayHeap_h
  5.  
  6. #ifndef ArrayOf_h
  7. #include "ArrayOf.h"
  8. #endif
  9.  
  10. template < class Element >
  11. class ArrayHeap
  12.   {
  13.     public:
  14.         typedef int32 (*Comparison)( const Element&, const Element& );
  15.     
  16.     private:
  17.         Element *heap;
  18.         uint32 lastElement;
  19.         const Comparison compare;
  20.         
  21.         void Sink( uint32 index );
  22.         void MakeHeap();
  23.         
  24.     public:
  25.         ArrayHeap( ArrayOf<Element>, Comparison );
  26.         
  27.         const Element& Top() const        { Assert( lastElement > 0 ); return heap[1]; }
  28.         void Pop();
  29.         
  30.         void Sort();
  31.   };
  32.  
  33. #ifndef ArrayHeap_cp
  34. #include "ArrayHeap.cp"
  35. #endif
  36.  
  37. #endif
  38.